package com.example.asus.swipelayouttest;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private SwipeLayout sls;
    private LinearLayout lls;
    private TextView tvDelete,tvFouce;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }


    private void initView(){

        sls = findViewById(R.id.sls);
        lls = findViewById(R.id.lls);
        tvDelete = findViewById(R.id.tv_delete);
        tvFouce = findViewById(R.id.tv_focus);

        sls.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (SwipeLayoutManger.getInstance().hasOpenSwipeLayout())
                    SwipeLayoutManger.getInstance().closeOpenSwipeLayout();
            }
        });


        sls.setListener(new SwipeLayout.OnSwipLayoutChangeListener() {
            @Override
            public void open() {

            }

            @Override
            public void close() {

            }

            @Override
            public void move(int x, int max) {

            }
        });


        tvDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this,"删除",Toast.LENGTH_SHORT).show();
                if (SwipeLayoutManger.getInstance().hasOpenSwipeLayout())
                    SwipeLayoutManger.getInstance().closeOpenSwipeLayout();
            }
        });

        tvFouce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this,"关注",Toast.LENGTH_SHORT).show();
                if (SwipeLayoutManger.getInstance().hasOpenSwipeLayout())
                    SwipeLayoutManger.getInstance().closeOpenSwipeLayout();
            }
        });

        sls.post(new Runnable() {
            @Override
            public void run() {
                lls.getLayoutParams().height = sls.getMeasuredHeight();
                lls.requestLayout();
            }
        });

    }
}
